package pl.nazaweb.imedproplus.model;

public class EntityFactory {
        
        private static final String PACKAGE_NAME = "pl.nazaweb.imedproplus.model.entity";
    
        public static Object newInstance(Class interfaceClass) {
        String className = getClassNameByInterface(interfaceClass);
        try {
            return Class.forName(className).newInstance();
        }
        catch(Exception e) {
            return null;
        }
    }
    
    private static String getClassNameByInterface(Class interfaceClass) {
        String simpleInterfaceName = interfaceClass.getSimpleName();
        String className = simpleInterfaceName.substring(1);
        return PACKAGE_NAME.concat(".").concat(className);
    }
}
